<html><script src="../../js/angular1.3.min.js"></script>
<style>
    input.ng-invalid {
        border: 1px solid red;
        background-color: pink;
    }
    input.ng-valid {
        border: 1px solid green;
        background-color: lightgreen;
    }

</style>
<body ng-app="docsTimeDirective">
<div ng-controller="Controller">
    Date format: <input ng-model="format" id="inptest" my-current-time> <hr/>
    {{format}}
</div>

</body>  </html>
<script>
    angular.module('docsTimeDirective', [])
  .controller('Controller', ['$scope', function($scope) {          $scope.format = 'M/d/yy h:mm:ss a';           }])
  .directive('myCurrentTime', function() {
                function link(scope, element, attrs, actr) {
                    console.log('link parsers to datetime ' + element[0].id);
                    console.log(element);
                    console.log(attrs);
                    actr.$parsers.unshift(function (viewValue) {
                            var lstime = new Date(viewValue);
                            console.log(lstime);
                            if ( lstime.getFullYear()>2000 && lstime.getMonth() >=0 && lstime.getDate() >=0    )
                            {   actr.$setValidity('format', true);
                                return viewValue;}
                            else {
                                actr.$setValidity('format', false);
                                return undefined;}
                        });


                    /*scope.$watch(attrs.ngModel, function(value, valueold) {
                        console.log(value + ' -- ' + valueold);
                        try{
                            var lstime = new Date(value);
                            console.log(lstime);
                            actr.$setValidity('datetimeformat', false);
                            if ( lstime.getFullYear()>2000 && lstime.getMonth() >=0 && lstime.getDate() >=0    )
                                actr.$setValidity('format', true);
                            else
                                actr.$setValidity('format', false);
                        }
                        catch (e){
                            console.log(e.description);
                            //actr.$setValidity('format', false);
                        }

                    });*/
                }
                return {
                    require:"ngModel",
                    link: link
                };
            });

</script>